﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using System.Configuration;
using System.Data;
using TGIApp.Model;

namespace TGIApp.Web.Controllers
{
    public class OrganizerController : Controller
    {
        //
        // GET: /Organizer/

        public ActionResult Index()
        {
            var proxy = new Proxy.ServiceProxy();
            var clients = proxy.GetAllClients();
            return View(clients);
        }

        //
        // GET: /Organizer/Details/5

        public ActionResult Details(int id)
        {
            var proxy = new Proxy.ServiceProxy();
            var client = proxy.GetClientById(id);
            return View(client);
        }

        //
        // GET: /Organizer/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Organizer/Create

        [HttpPost]
        public ActionResult Create(User organizer)
        {

            if (ModelState.IsValid)
            {
                ITgiService proxy = new Proxy.ServiceProxy();
                proxy.CreateClient(organizer);
            }
            return RedirectToAction("Index");

        }

        //
        // GET: /Organizer/Edit/5

        public ActionResult Edit(int id)
        {

            ITgiService proxy = new Proxy.ServiceProxy();
            User organizer = proxy.GetClientById(id);
            return View(organizer);
        }

        //
        // POST: /Organizer/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, User organizer)
        {

            if (ModelState.IsValid)
            {
                ITgiService proxy = new Proxy.ServiceProxy();
                proxy.UpdateClient(organizer);
            }
            return RedirectToAction("Index");

        }

        //
        // GET: /Organizer/Delete/5

        public ActionResult Delete(int id)
        {
            ITgiService proxy = new Proxy.ServiceProxy();
            var organizer= proxy.GetClientById(id);
            return View(organizer);
        }

        //
        // POST: /Organizer/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, User organizerToBeDeleted)
        {
            ITgiService proxy = new Proxy.ServiceProxy();
            proxy.DeleteClientById(id);
            return RedirectToAction("Index");
        }
    }
}
